<?php

namespace addons\yunpian;
use think\Addons;

class Yunpian extends Addons
{
    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {
        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {
        return true;
    }

    /**
     * 短信发送行为
     * @param   Sms     $params
     * @return  boolean
     */
    public function smsSend(&$params)
    {
        if(!isset($params['tpl_id']))
            $params['tpl_id'] = 1;

        $sms = new library\Yunpian();
        $result = $sms->mobile($params->mobile)
                ->template($params->tpl_id)
                ->param(['code' => $params->code])
                ->send();
        return $result;
    }

    /**
     * 短信发送通知
     * @param   array   $params
     * @return  boolean
     */
    public function smsNotice(&$params)
    {
        $sms = library\Yunpian::instance();
        $result = $sms->mobile($params->mobile)  
                ->template($params->tpl_id)
                ->param($params)
                ->send();
        return $result;
    }

    /**
     * 检测验证是否正确
     * @param   Sms $params
     * @return  boolean
     */
    public function smsCheck(&$params)
    {
        return TRUE;
    }
}